package com.wrh.springboot.restwrap.propertyeditor;

import java.beans.PropertyEditorSupport;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author wrh
 */
public class CustomLocalDateEditor extends PropertyEditorSupport {

    private String fmt;

    public CustomLocalDateEditor(String fmt) {
        this.fmt = fmt;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(this.fmt);
        LocalDate localDate = LocalDate.parse(text, formatter);
        super.setValue(localDate);
    }
}
